package com.rabbitmq.demo.listener;

import com.rabbitmq.client.Channel;
import com.rabbitmq.demo.conf.RPCQueueConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * RPC模式消费者
 *
 * @Author yi.cheng
 * @Date 2023-7-17 10:04
 **/
@Slf4j
@Component
public class RPCQueueConsumer {
    @RabbitListener(queues = RPCQueueConfig.RPC_QUEUE_ONE)
    public String scanCodeRPCListener(Message message){
        //将byte数组转string类型
        String content = new String(message.getBody());
        String correlationId = message.getMessageProperties().getCorrelationId();
        log.info("rpc 模式收到的消息：{}; 消息的correlationId是：{}",content,correlationId);
        return "success";
    }
}
